function itemStateChange() {

	var searchBy_value = document.getElementById('search_type').value;
	var label = document.getElementById('searchBy_label');

	if (searchBy_value == 1) {
		label.innerHTML = "กรุณาป้อนรหัสอ้างอิงที่ต้องการค้นหาข้อมูล&nbsp;&nbsp;";
		document.getElementById('inputField').style.display = "inline";
		document.getElementById('dete_start').style.display = "none";
		document.getElementById('inputCombo').style.display = "none";
	} else if (searchBy_value == 2) {
		label.innerHTML = "กรุณาป้อนชื่อที่ต้องการค้นหาข้อมูล&nbsp;&nbsp;";
		document.getElementById('inputField').style.display = "inline";
		document.getElementById('dete_start').style.display = "none";
		document.getElementById('inputCombo').style.display = "none";
	} else if (searchBy_value == 3) {
		label.innerHTML = "กรุณาป้อนวันที่ต้องการค้นหาข้อมูล&nbsp;&nbsp;";
		document.getElementById('inputField').style.display = "none";
		document.getElementById('inputCombo').style.display = "none";
		document.getElementById('dete_start').style.display = "inline";
	} else if (searchBy_value == 4) {
		label.innerHTML = "กรุณาป้อนจำนวนคนที่จองโตีะอาหาร&nbsp;&nbsp;";
		document.getElementById('inputField').style.display = "none";
		document.getElementById('dete_start').style.display = "none";
		document.getElementById('inputCombo').style.display = "inline";
	} else {
		return;
	}
}

function getData() {
	var searchBy_value = document.getElementById('search_type').value;
	
	if (searchBy_value == 1) {
		var refNo_value = document.getElementById('data_input').value;
		
		if(isNaN(refNo_value) || refNo_value.length != 6) {
			alert("คุณป้อนรหัสยืนยันไม่ถุกต้อง");
			document.getElementById('data_input').focus();
			return false;
		} else {
			callDB(1,refNo_value);
		}
	} else if (searchBy_value == 2) {
		var name_value = document.getElementById('data_input').value;
		
		if(!isNaN(name_value) || name_value.length <= 0) {
			alert("คุณป้อนชื่อที่ต้องการค้นหาไม่ถุกต้อง");
			document.getElementById('data_input').focus();
			return false;
		} else {
			callDB(2,name_value);
		}
	} else if (searchBy_value == 3) {
		var date_value = document.getElementById('dete_start').value;
		
		if(date_value <= 0) {
			return false;
		}else {
			var frontDate_value = date_value.split(" ")[0];
			var dayStart = frontDate_value.split("/")[1];
			var mountStart = frontDate_value.split("/")[0];
			var yearStart = frontDate_value.split("/")[2];	
			var result_value = yearStart + "-" + mountStart + "-" + dayStart;
			
			callDB(3,result_value);
		}
	} else if (searchBy_value == 4) {
		var people_value = document.getElementById('inputCombo').value;
		
			if(people_value < 1 && people_value > 6) {
				alert("ข้อมูลที่ป้อนมาไม่ถุกต้อง");
				return false;
			} else {
				callDB(4,people_value);
			}
	} else {
		return;
	}
}

function callDB(data_type,data_value) {
	
	document.getElementById('indicator').style.display = 'block';
	
	var URL = "search_process.php";
	data = "type=" + data_type + "&value=" + data_value;

	//alert(data);
	// connect to table_status.php by ajaxframework
	ajaxLoad("post", URL, data, "result_area");
}